/**
 * 
 */
package com.cmcc.pcap.packet.util;

import java.util.LinkedList;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @Date 2018年6月14日 下午1:56:47
 * @author Amish
 */
public class CommonStatistics implements Statistics{
	
	private static CommonStatistics instance= new CommonStatistics();
    public static CommonStatistics getInstance() {
    	return instance;
    }
	
    
    private CommonStatistics() {
    	//httpRequestSegmentNumStat = new LinkedList<String>();
    	httpTransactionNum = new AtomicInteger(0);
    	httpEntityNum = new AtomicInteger(0);
    }
    

    LinkedList<String> httpRequestSegmentNumStat;
    
    public synchronized void addHttpRequestSegemntNumStat(String str) {
    	httpRequestSegmentNumStat.add(str);
    }
    
    public String httpRequestSegmentNumStatToString() {
    	StringBuilder sb = new StringBuilder();
    	sb.append("\n [Http Request Segement Num Stat : ] ");
    	sb.append("\n Summary is : ");
    	sb.append(httpRequestSegmentNumStat.size());
    	for(String str : httpRequestSegmentNumStat) {
    		sb.append("\n ");
    		sb.append(str);
    	}
    	return sb.toString();
    }
    
    
    
    public AtomicInteger httpTransactionNum;
    
    public synchronized void addHttpTransactionNum(int num) {
    	httpTransactionNum.getAndAdd(num);
    }
    
    public String HttpTransactionNumToString() {
    	return "\n [Http Transaction Number is : ] "+httpTransactionNum.get();
    }
    
    public AtomicInteger httpEntityNum;
    public synchronized void addHttpEntityNum(int num) {
    	httpEntityNum.getAndAdd(num);
    }
    
    public String HttpEntityNumToString() {
    	return "\n [Http Entity Number is : ] "+httpEntityNum.get();
    }
    
    /**
	 * 统计数据清零
	 */
	public void reset() {
		//httpRequestSegmentNumStat.clear();
		httpTransactionNum.set(0);
		httpEntityNum.set(0);
	}
    
    
    public String toString() {
    	StringBuilder sb = new StringBuilder();
    	
    	sb.append(HttpTransactionNumToString());
//    	sb.append("\n------------------------------------------------------------------------------");
//    	sb.append(httpRequestSegmentNumStatToString());
    	
    	return sb.toString();
    }
    
    
    
}
